/*--------------------------------------------------------------------------
Modified from GNU Group's SDCC
Only for study purpose
---------------------------------------------------------------------------*/

/*-----------------------------------------------------------------*/
/* ccmem.h - header file for memory management                     */
/* reference from SDCCmem.h                                        */
/*-----------------------------------------------------------------*/

#ifndef __COMPILER_GROUP_CCMEM_H
#define __COMPILER_GROUP_CCMEM_H

#include "Support\dbuf.h"

typedef struct memmap
{
    const char *sname;          /* character prefix for map        */
    unsigned sloc;              /* starting location               */
    unsigned codesp:1;          /* 1 = code space                  */
    struct set *syms;           /* symbols defined in this segment */
} memmap;

extern memmap *stack;           /* program stack                */
extern memmap *code;            /* code segment                 */
extern memmap *data;            /* internal data                */

extern int fatalError;

/* module management */
memmap *allocMap (unsigned, const char *, char);
void initMem ();

/* memory management */
int allocVariables (symbol *);
void allocLocal (symbol *);
void allocGlobal (symbol *);
void allocParms (value *);
void allocIntoSeg (symbol *);
bool defaultOClass (symbol *);

/* for debug */
void viewSeg(FILE *fp, memmap *mem);
void viewStackSeg(FILE *fp);
void fprintMemToFile(char *file);

#endif